<template>
    <div>
        <!--导航栏-->
        <div style="position: fixed;z-index: 10;width: 100%">
            <van-nav-bar  title="注册" left-text="" left-arrow @click-left="onClickLeft()">
                <template #right>
                    <van-icon name="search" size="18" />
                </template>
            </van-nav-bar>
        </div>
        <div style="height: 50px"></div>

        <van-form @submit="onSubmit">
            <van-field
                    v-model="username"
                    name="username"
                    label="用户名"
                    placeholder="用户名"
                    :rules="[{ required: true, message: '请填写用户名' }]"
            />
            <van-field
                    v-model="pwd1"
                    type="password"
                    name="pwd1"
                    label="密码"
                    placeholder="密码"
                    :rules="[{ required: true, message: '请填写密码' }]"
            />
            <van-field
                    v-model="pwd2"
                    type="password"
                    name="pwd2"
                    label="确认密码"
                    placeholder="密码"
                    :rules="[{ required: true, message: '请填写密码' }]"
            />
            <div style="margin: 16px;">
                <van-button round block type="info" native-type="submit">
                    提交
                </van-button>
            </div>
        </van-form>
    </div>
</template>

<script>
    export default {
        name: "Register",
        data(){
            return {
                username: '',
                pwd1: '',
                pwd2: '',
            }
        },
        methods:{
            onClickLeft(){
                this.$router.back();
            },
            onSubmit(value){
                if(value.pwd1!==value.pwd2){
                    alert('密码不一致');
                    this.pwd1='';
                    this.pwd2='';
                }
                else{
                    // this.$router.back()
                    this.$axios.post('/registerBuyer',{
                        username: this.username,
                        password: this.pwd1
                    }).then(res=>{
                        if(res.data.code == 200){
                            console.log(res.data.message);
                            this.$router.back()
                        } else {
                            console.log(res.data.message);
                        }
                    })
                }
            }
        }
    }
</script>

<style scoped>

</style>